/*
 * pfs.c
 *
 *  Created on: 13/09/2011
 *      Author: ronald mc donald
 */

#include <pthread.h>
#include "./includes/FuncionesArchConfig.h"
#include "./includes/funcionesConsola.h"
#include "../../Commons/src/includes/BibliotecasGenerales.h"
#include "includes/utilesConexion.h"
#include "./includes/funcionesUtiles.h"
#include "./includes/funcionesFat.h"
#include "./includes/estructuraFAT.h"
#include "./includes/variablesGlobales.h"
#include "./includes/utils.h"
#include "./includes/cacheArchivos.h"
#include "includes/fuse.h"
#include <fuse.h>

struct fuse_operations operaciones_con_fuse = {  //Meto aca sino no compila!!

		.getattr = fuse_getattr,
		.mkdir = fuse_mkdir,
		.create = fuse_create,
		.unlink = fuse_unlink,
		.rmdir = fuse_rmdir,
		.rename = fuse_rename,
		.open = fuse_open,
		.read = fuse_read,
		.write = fuse_write,
		.flush = fuse_flush,
		.release = fuse_release,
		.readdir = fuse_readdir,
		.truncate = fuse_truncate,
};

//void print(int signal){
//	printf("Esto tiro la señal SIGUSR1");
//}



int main(int argc, char **argv){

	listaRaiz=NULL;
	listaCacheArchivos=NULL;
	int32_t dir;
	int32_t elem,gilada;
	int32_t *tablafatonga=NULL;
	char *clusterBootSec;
	char *clusterLeido;
	char *buffer;
	pthread_t thread;
	buffer=calloc(1,100);

	flagRAID = 0;
	cantConex=cantConex+2;

	//Inicializar los mutex

	pthread_mutex_init(&mutexFat, NULL);
	pthread_mutex_init(&mutexRaiz, NULL);
	cargarArchivoDeConfiguracion();

	buffer=calloc(1,10*4096);


	clusterBootSec=leerCluster(0);
	bootSector=inicializarBootSector(clusterBootSec,bootSector);


	dir=obtenerDirDelCluster(bootSector.cluster_raiz,bootSector);



	signal(SIGUSR1,&imprimirCache);
	//raise(SIGUSR1);



	clusterLeido=leerCluster(dir);

	elem=agregarAListaRaiz(&listaRaiz,clusterLeido);


	tablaFat=inicializarTablaFAT(bootSector);

	tablafatonga=tablaFat;

	pthread_create(&thread,NULL,(void *)&consolaPrincipal,NULL);



	return fuse_main(argc,argv,&operaciones_con_fuse);

}








